package com.handinglian.ai.system.service.impl;

import com.handinglian.ai.system.entity.RolePermissionRelation;
import com.handinglian.ai.system.mapper.RolePermissionRelationMapper;
import com.handinglian.ai.system.service.RolePermissionRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("rolePermissionService")
public class RolePermissionRelationServiceImpl implements RolePermissionRelationService {
    @Autowired
    private RolePermissionRelationMapper rolePermissionRelationMapper;

    @Override
    @Transactional
    public int createBatch(List<RolePermissionRelation> list) {
        return rolePermissionRelationMapper.batchInsert(list);
    }

    @Override
    @Transactional
    public int deleteByRoleId(Integer roleId) {
        return rolePermissionRelationMapper.deleteByRoleId(roleId);
    }

    @Override
    public List<Integer> listPermissionId(Integer roleId) {
        return rolePermissionRelationMapper.findPermissionIdByRoleId(roleId);
    }

    @Override
    @Transactional
    public int delete(Integer roleId, List<Integer> permissionIds) {
        return rolePermissionRelationMapper.deleteByRoleIdAndPermissionIdIn(roleId, permissionIds);
    }
}
